package com.yueyue.h2.controller;


import com.yueyue.h2.entity.User;
import com.yueyue.h2.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private UserMapper userMapper;

    @PostMapping("/save")
    public String save(@RequestBody User user) {
//        String insertUserData = "insert into user(name,age) values (?,?)";
//        jdbcTemplate.update(insertUserData, user.getName(), user.getAge());


        userMapper.insert(user);

        return "success";
    }


//    @PostMapping("/list")
//    public List<Map<String, Object>> list() {
//        String selectUserData = "select * from user";
//        return jdbcTemplate.queryForList(selectUserData);
//    }
    @PostMapping("/list")
    public List<User> list() {
        return userMapper.selectList(null);
    }
}
